package com.twotiger.and.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.alibaba.fastjson.JSON;
import com.twotiger.and.bean.ExperienceProjectDetail;
import com.twotiger.and.bean.InvestList;
import com.twotiger.and.bean.ProjectDetail;
import com.twotiger.and.bean.ProjectdetailData;
import com.twotiger.and.util.DateUtil;
import com.twotiger.and.util.ListUtils;

public class ExperienceProjectInvestlistAdapter extends BaseAdapter {
    private ExperienceProjectDetail projectDetail;
    private List<InvestList> investLists;
    private LayoutInflater inflater;
    private Context context;

    public ExperienceProjectInvestlistAdapter(Context context, ExperienceProjectDetail projectDetail) {
        super();
        this.projectDetail = projectDetail;
        this.context = context;
        this.investLists = JSON.parseArray(projectDetail.getInvestList(), InvestList.class);
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (!ListUtils.isEmpty(investLists)) {
            return investLists.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MViewholder mViewHolder;
        final int index = position;
        if (convertView == null) {
            mViewHolder = new MViewholder();
            convertView = inflater.inflate(R.layout.project_detail_item2_list_item2, null);
            mViewHolder.repay_time = (TextView) convertView.findViewById(R.id.item_text_1);
            mViewHolder.repay_type = (TextView) convertView.findViewById(R.id.item_text_2);
            mViewHolder.repay_amount = (TextView) convertView.findViewById(R.id.item_text_3);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (MViewholder) convertView.getTag();
        }
        InvestList invest = investLists.get(index);
        mViewHolder.repay_type.setText(invest.getAmount());
        mViewHolder.repay_time.setText(invest.getCustomerName());
        mViewHolder.repay_amount.setText(DateUtil.getDateStringForLong(Long.valueOf(invest.getUtime()), DateUtil.FMT));
        return convertView;
    }

    class MViewholder {
        public TextView repay_amount;
        public TextView repay_type;
        public TextView repay_time;

    }
}
